import { Component, PropTypes } from '@didi/teddy-immutable'
import FormItem from '../form-item/form-item'
import tool from '../../common/tool'

const {
  makeid
} = tool
const { array } = PropTypes

class FormList extends Component {
  static propTypes = {
    items: array
  }

  static defaultProps = {
    items: []
  }

  children() {
    return {
      listItems: this.props.items.asMutable({deep:true}).map((item) => {
        return {
          component: FormItem,
          key: item.id || makeid(),
          props: item
        }
      })
    }
  }
}

export default FormList